<template>
    <f7-page ptr
             @ptr:refresh="refresh"
             infinite
             :infinite-distance="50"
             :infinite-preloader="true"
             @infinite="infinite">
        <f7-navbar>
            <f7-nav-left>
                <f7-link back>
                    <i class="nav-icon__back f7-icons">chevron_left</i>
                </f7-link>
            </f7-nav-left>
            <f7-nav-title>待办事项</f7-nav-title>
            <f7-nav-right></f7-nav-right>
        </f7-navbar>
        <qm-tabs v-model="activeName"
                 titleCenter>
            <qm-tab title="待办事项"
                    name="toDoList">
                <f7-block v-if="query.data.length > 0">
                    <qm-entrust-card v-for="item in query.data"
                                     :key="item.taskId"
                                     @click.native="handleEdit(item)"
                                     :title="item.instanceTitle"
                                     :operator="item.taskName"
                                     :date="item.startTime.substring(0, 10)"></qm-entrust-card>
                </f7-block>
                <qm-blankPage v-else
                              :src="'static/img/blankpage/black/no-data.png'"
                              blanktitle="暂无数据～"
                              @click="searchQuery"></qm-blankPage>
            </qm-tab>
            <qm-tab title="已办事项"
                    name="doneList">
                <f7-block v-if="query$1.data.length > 0">
                    <qm-entrust-card v-for="item in query$1.data"
                                     :key="item.taskId"
                                     @click.native="handleView(item)"
                                     :title="item.instanceTitle"
                                     :operator="item.taskName"
                                     :date="item.finishTime.substring(0, 10)"></qm-entrust-card>
                </f7-block>
                <qm-blankPage v-else
                              :src="'static/img/blankpage/black/no-data.png'"
                              blanktitle="暂无数据～"
                              @click="searchQuery"></qm-blankPage>
            </qm-tab>
        </qm-tabs>
    </f7-page>
</template>
<script>
import controller from "@/libs/framework/controller";

export default class instance extends controller {
    // enableBackRequest () {
    //     return false
    // }
    disableCache () {
        return false
    }
    onBeforeInit () {
        this.urls = {
            query: ["/workflow/toDoList/query", "/workflow/doneList/query"],
            model: "/workflow/toDoList/getListModel",
        };
    }

    onBeforeQuery (type, conditions, params) { }

    onAfterQuery (type, isSuccess, result) {
        return result;
    }

    onBinded (data, context) {
        return context;
    }

    mixin () {
        return {
            data () {
                return {
                    activeName: "toDoList",
                };
            },
            methods: {
                handleEdit (item) {
                    this.$f7.preloader.show();
                    if (item.aspType == "ASPTODO") {
                        let tparams = JSON.parse(item.thirdParams);
                        let wparams = JSON.parse(item.workflowParams);
                        if (wparams && wparams.action && ['processEdit', 'processView'].includes(wparams.action)) {
                            //工作流
                            this.getWorkflowArgs({ formId: params.formid }).then((r) => {
                                this.$f7.preloader.hide();
                                this.$f7.views.current.router.navigate(
                                    `${r.appUrl}?taskId=${item.taskId}&assigneeId=${item.assigneeId}&action=processEdit&pageAction=view&appCode=${item.appCode}&version=${r.version}`
                                );
                            }).catch((err) => {
                                this.$f7.preloader.hide();
                                this.$f7.dialog.alert("失败，请稍后再试");
                            });
                        } else {
                            //非工作流、或新增工作流
                            let url = ((wparams.action && wparams.action != 'view') ? item.appEditUrl : item.appViewUrl) || item.defaultUrl;
                            url = url.indexOf("?") > -1 ? url : url + "?";
                            Object.keys(tparams).forEach(key => {
                                url += `&${key}=${tparams[key]}`;
                            });
                            url += `&_itemId=${item.itemId}`;
                            this.$f7.views.current.router.navigate(url);
                        }
                    } else {
                        this.getWorkflowArgs({ taskId: item.taskId }).then((r) => {
                            this.$f7.preloader.hide();
                            this.$f7.views.current.router.navigate(
                                `${r.appUrl}?taskId=${item.taskId}&assigneeId=${item.assigneeId}&action=processEdit&pageAction=view&appCode=${item.appCode}&version=${r.version}`
                            );
                        }).catch((err) => {
                            this.$f7.preloader.hide();
                            this.$f7.dialog.alert("失败，请稍后再试");
                        });
                    }
                },
                handleView (item) {
                    this.$f7.preloader.show();
                    this.getWorkflowArgs({ taskId: item.taskId }).then((r) => {
                        this.$f7.preloader.hide();
                        this.$f7.views.current.router.navigate(
                            `${r.appUrl}?historyTaskId=${item.taskId}&action=processView&pageAction=view&appCode=${item.appCode}&version=${r.version}`
                        );
                    })
                        .catch((err) => {
                            this.$f7.preloader.hide();
                            this.$f7.dialog.alert("失败，请稍后再试");
                        });
                },
            },
        };
    }
}
</script>
<style lang="less" scoped>
.toDoMessage {
    font-size: var(--font-size-maintitle);
    color: var(--color-red);
    text-align: center;
}
/deep/.page-content {
    background-color: var(--color-fill-background);
}
</style>


